<include file="public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
  <script src="__PUBLIC__/js/laydate/laydate.js"></script>
<!--物流配置 css -start-->
<style>
    ul.group-list { width: 96%;min-width: 1000px; margin: auto 5px;list-style: disc outside none;}
    ul.group-list li {white-space: nowrap;float: left;width: 150px; height: 25px; padding: 3px 5px;list-style-type: none;list-style-position: outside;border: 0px;margin: 0px;}
</style>
<div class="wrapper">
    <include file="public/breadcrumb"/>
    <section class="content">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>商品详情</h3>
                </div>
                <div class="panel-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_tongyong" data-toggle="tab">通用信息</a></li>
                        <li><a href="#tab_goods_image" data-toggle="tab">商品图片</a></li>
                        <li><a href="#tab_goods_spec" data-toggle="tab">商品模型</a></li>
                    </ul>
                    <!--表单数据-->
                    <form method="post" id="addEditGoodsForm">
                    
                        <!--通用信息-->
                    <div class="tab-content">                 	  
                        <div class="tab-pane active" id="tab_tongyong">
                           
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td class="col-sm-2">商品名称:</td>
                                    <td class="col-sm-8">
                                        <input type="text" value="{$goodsInfo.goods_name}" name="goods_name" class="form-control" style="width:550px;"/>
                                        <span id="err_goods_name" style="color:#F00; display:none;"></span>                                        
                                    </td>
                                </tr>
                                <tr>
                                    <td class="col-sm-2">商品简单描述:</td>
                                    <td class="col-sm-8">
                                        <input type="text" value="{$goodsInfo.goods_remark}" name="goods_remark" class="form-control" style="width:550px;"/>
                                        <span id="err_goods_remark" style="color:#F00; display:none;"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="col-sm-2">商品分类:</td>
                                    <td class="col-sm-8">
                                        <div class="col-sm-4">
                                            <select name="cat_id" class="form-control">
                                                <option value="0">请选择商品分类</option>
                                                <volist name="cat_list" id="cat_list" >
                                                    <option value="{$cat_list.id}" <if condition="$goodsInfo['cat_id'] eq $cat_list['id']">selected="selected"</if> >
                                                    {$cat_list['name']}
                                                    </option>
                                                </volist>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="col-sm-2">商品原价:</td>
                                    <td class="col-sm-8">
                                        <div class="input-group">
                                            <input type="text" value="{$goodsInfo.original_price}" name="original_price" class="form-control" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                            <span class="input-group-addon">元/积分</span>
                                        </div>


                                    </td>
                                </tr>

                                <tr>
                                    <td class="col-sm-2">商品零售价:</td>
                                    <td class="col-sm-8">
                                        <div class="input-group">
                                            <input type="text" value="{$goodsInfo.shop_price}" name="shop_price" class="form-control" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" />
                                            <span class="input-group-addon">元/积分</span>
                                        </div>

                                    </td>
                                </tr>

                                <tr>
                                    <td class="col-sm-2">上传商品图片:</td>
                                    <td class="col-sm-8">
                                        <input type="button" value="上传图片"  onclick="GetUploadify(1,'','goods','call_back');"/>
                                        <input type="text" class="input-sm"  name="original_img" id="original_img" value="{$goodsInfo.original_img}"/>
                                        <!--<if condition="$goodsInfo['original_img'] neq null">-->
                                            <!--&nbsp;&nbsp;-->
                                            <!--<a target="_blank" href="{$goodsInfo.original_img}" id="original_img2">-->
                                                <!--<img width="25" height="25" src="{$goodsInfo.original_img}">-->
                                            <!--</a>-->
                                        <!--</if>-->
                                        <span style="color:#F00;">详情页图片建议尺寸430 x 430</span>
                                    </td>
                                </tr>


                                <tr>
                                    <td class="col-sm-2">商品介绍：</td>
                                    <td class="col-sm-8">
                                        <textarea class="span12 ckeditor" id="post_content" name="content" title="">{$goodsInfo.content}</textarea>
                                    </td>
                                </tr>
                                </tbody>                                
                                </table>
                        </div>
                         <!--其他信息-->

                        <!-- 商品规格-->
                        <div class="tab-pane" id="tab_goods_spec">
                            <table class="table table-bordered" id="goods_spec_table">
                                <tr>
                                    <td class="col-sm-2">商品模型:</td>
                                    <td class="col-sm-8">
                                        <select name="goods_type" id="spec_type" class="form-control" style="width:250px;">
                                            <option value="0">选择商品模型</option>
                                            <foreach name="goodsType" item="vo" key="k" >
                                                <option value="{$vo.id}"<if condition="$goodsInfo.goods_type eq $vo.id"> selected="selected" </if> >{$vo.name}</option>
                                            </foreach>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                            <div class="row">
                                <!-- ajax 返回规格-->
                                <div id="ajax_spec_data" class="col-xs-8" style="border:1px solid #ddd;"></div>
                            </div>
                        </div>
                        <!-- 商品规格-->


						<!--商品图片-->
						<div class="tab-pane" id="tab_goods_image">
                            <tr>
								<td>
									<div class="form-group">
									 
									  <div class="col-sm-8">
										  <foreach name="$image" item="vo" key="k" >
											  <div style="width:100px; text-align:center; margin: 5px; display:inline-block;" class="goods_img">
												  <input type="hidden" value="{$vo}" name="image[]">
												  <a onclick="" href="{$vo}" target="_blank"><img width="100" height="100" src="{$vo}"></a>
												  <br>
												  <a href="javascript:void(0)" onclick="ClearPicArr4(this)">删除</a>
											  </div>
										  </foreach>
										  <div class="goods_img" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
											  <input type="hidden" name="image[]" value="" />
											  <a href="javascript:void(0);" onclick="GetUploadify(1,'','goods','call_back4');"><img src="/public/images/add-button.jpg" width="100" height="100" /></a>
											  <br/>
											  <a href="javascript:void(0)">&nbsp;&nbsp;</a>
										  </div>
									  </div>
								  </div>
								  <span id="err_original_img" style="color:#F00;">详情页图片建议尺寸430 x 430</span>
								</td>	
							</tr>	
                        </div>
                    </div>


                    <div class="pull-right" style="margin-right: 50%;margin-top: 20px;">
                        <input type="hidden" name="goods_id" value="{$goodsInfo.goods_id}">
                        <input type="hidden" name="__token__" value="{$Request.token}" />                        
                        <button class="btn btn-primary" onclick="ajax_submit_form('addEditGoodsForm','{:U('Goods/addEditGoods?is_ajax=1')}');" title="" data-toggle="tooltip" type="button" data-original-title="保存">保存</button>
                    </div>
			    </form><!--表单数据-->
                </div>
            </div>
        </div>    <!-- /.content -->
    </section>
</div>
<script>
    $(document).ready(function(){
        $(":checkbox[cka]").click(function(){
            var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
            if($(this).is(':checked')){
                $cks.each(function(){$(this).prop("checked",true);});
            }else{
                $cks.each(function(){$(this).removeAttr('checked');});
            }
        });
    });

    var url="{:url('Ueditor/index',array('savePath'=>'article'))}";
    var ue = UE.getEditor('post_content',{
        serverUrl :url,
        zIndex: 999,
        initialFrameWidth: "100%",
        initialFrameHeight: 300,
        focus: false,
        maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',
        pasteplain:false,
        autoHeightEnabled: true,
        allowDivTransToP: false
    });

    function choosebox(o){
        var vt = $(o).is(':checked');
        if(vt){
            $('input[type=checkbox]').prop('checked',vt);
        }else{
            $('input[type=checkbox]').removeAttr('checked');
        }
    }
    /*
     * 以下是图片上传方法
     */
    // 上传商品图片成功回调函数
    function call_back(fileurl_tmp){
        $("#original_img").val(fileurl_tmp);
        $("#original_img2").attr('href', fileurl_tmp);
    }
    /** 以下 商品属性相关 js*/

// 属性输入框的加减事件
    function addAttr(a)
    {
        var attr = $(a).parent().parent().prop("outerHTML");
        attr = attr.replace('addAttr','delAttr').replace('+','-');
        $(a).parent().parent().after(attr);
    }
    // 属性输入框的加减事件
    function delAttr(a)
    {
        $(a).parent().parent().remove();
    }


    /** 以下 商品规格相关 js*/
    $(document).ready(function(){
        // 商品模型切换时 ajax 调用  返回不同的属性输入框
        $("#spec_type").change(function(){
            var goods_id = '{$goodsInfo.goods_id}';
            var spec_type = $(this).val();
            $.ajax({
                type:'GET',
                data:{goods_id:goods_id,spec_type:spec_type},
                url:"{:U('Goods/ajaxGetSpecSelect')}",
                success:function(data){
                    $("#ajax_spec_data").html('')
                    $("#ajax_spec_data").append(data);
                    ajaxGetSpecInput();	// 触发完  马上触发 规格输入框
                }
            });
        });
        // 触发商品规格
        $("#spec_type").trigger('change');

        $("input[name='exchange_integral']").blur(function(){
            var shop_price = parseInt($("input[name='shop_price']").val());
            var exchange_integral = parseInt($(this).val());
            if (shop_price * 100 < exchange_integral) {

            }
        });
    });
// 上传商品相册回调函数
function call_back2(paths){

	 var  last_div = $(".goods_xc:last").prop("outerHTML");

	$(".goods_xc:eq(0)").before(last_div);	// 插入一个 新图片
	$(".goods_xc:eq(0)").find('a:eq(0)').attr('href',paths).attr('onclick','').attr('target', "_blank");// 修改他的链接地址
	$(".goods_xc:eq(0)").find('img').attr('src',paths);// 修改他的图片路径
	$(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick',"ClearPicArr2(this,'"+paths+"')").text('删除');
	$(".goods_xc:eq(0)").find('input').val(paths); // 设置隐藏域 要提交的值

}

// 上传商品相册回调函数
function call_back4(paths){

	 var  last_div = $(".goods_img:last").prop("outerHTML");

	$(".goods_img:eq(0)").before(last_div);	// 插入一个 新图片
	$(".goods_img:eq(0)").find('a:eq(0)').attr('href',paths).attr('onclick','').attr('target', "_blank");// 修改他的链接地址
	$(".goods_img:eq(0)").find('img').attr('src',paths);// 修改他的图片路径
	$(".goods_img:eq(0)").find('a:eq(1)').attr('onclick',"ClearPicArr4(this,'"+paths+"')").text('删除');
	$(".goods_img:eq(0)").find('input').val(paths); // 设置隐藏域 要提交的值

}
/*
 * 上传之后删除组图input
 * @access   public
 * @val      string  删除的图片input
 */
function ClearPicArr2(obj)
{
	$(obj).parent().remove(); // 删除完服务器的, 再删除 html上的图片

}

function ClearPicArr4(obj)
{
	$(obj).parent().remove(); // 删除完服务器的, 再删除 html上的图片

}
</script>
</body>
</html>